﻿namespace Xioa_UI.Domain;

public static class GetRunValue
{
    public static KeyValuePair<string, string>? GetRunningKeyValuePair<T>(T data)
    {
        var typeList = CarryOut.TypesTOne;

        if (typeList == null) return null;
        foreach (var item in typeList)
        {
            var resType = item.GetInterfaces().Any(i =>
                i == typeof(IAlternateNesting<T>));
            if (!resType) continue;
            var result = (Activator.CreateInstance(item)
                as IAlternateNesting<T>)?.GetNestRunningString(data);

            if (result is not null && result.Value.Item3)
                return new KeyValuePair<string, string>(result.Value.Item1, result.Value.Item2);
        }

        return new KeyValuePair<string, string>("", "");
    }


    public static KeyValuePair<string, string>? GetRunningKeyValuePair<T, TResult>(T data)
    {
        var typeList = CarryOut.TypesTTwo;

        if (typeList == null) return null;
        foreach (var item in typeList)
        {
            var resType = item.GetInterfaces().Any(i =>
                i == typeof(IAlternateNesting<T, TResult>));
            if (!resType) continue;
            var result = (Activator.CreateInstance(item)
                as IAlternateNesting<T, TResult>)?.GetNestRunningString(data);

            if (result is not null && result.Value.Item3)
                return new KeyValuePair<string, string>(result.Value.Item1, result.Value.Item2);
        }

        return new KeyValuePair<string, string>("", "");
    }
}